import { createRouter, createWebHashHistory } from "vue-router";
import home from "@/components/HelloWorld.vue";

const routes = [
  {
    path: "/", //路径描述
    name: "home",
    component: home // 主动引用，无论是否访问均加载页面
  },
  {
    path: "/about",
    name: "about",
    component: () => import("@/view/about.vue")// 异步加载的路由的组件位置,只有页面被访问才加载
  }
]

const router = createRouter({
  history: createWebHashHistory(), // 跳转方式
  routes: routes // 路由配置
})

router.beforeEach((to, from, next) => {

  const data = routes.find(item => item.path === to.path)
  if (!data && to.path !== '/about') {
    router.setDefaultPage({ name: 'my-selint', path: data.path })//判断是否是子应用内跳转，如果不写的话，点击浏览器自带返回按钮页面为空
  }
  // 每次路由跳转前执行
  next()
})
export default router